using System;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI;
using Jbe.TestSuite.Infrastructure.Interface;
using Microsoft.Practices.CompositeUI.Utility;
using Microsoft.Practices.CompositeUI.EventBroker;
using Jbe.TestSuite.Help.Constants;

namespace Jbe.TestSuite.Help
{
    public partial class HelpViewPresenter : Presenter<IHelpView>
    {
        private Uri homeUrl;

        public Uri HomeUrl
        {
            get { return homeUrl; }
        }

        /// <summary>
        /// This method is a placeholder that will be called by the view when it has been loaded.
        /// </summary>
        public override void OnViewReady()
        {
            base.OnViewReady();
        }

        /// <summary>
        /// Close the view
        /// </summary>
        public void OnCloseView()
        {
            base.CloseView();
        }

        [EventSubscription(EventTopicNames.HelpUriUpdate, Thread=ThreadOption.UserInterface)]
        public void HelpUriUpdateHandler(object sender, DataEventArgs<Uri> eventArgs) 
        {
            if (homeUrl == null)
            {
                homeUrl = eventArgs.Data;
                View.HomeUrlChanged();
            }
            View.UpdateHelpUrl(eventArgs.Data);
        }
    }
}

